package org.etcsoft.examples.saniker;

import java.io.File;

import org.eclipse.jface.viewers.CellEditor;
import org.eclipse.jface.viewers.EditingSupport;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.jface.viewers.TextCellEditor;

public class fileNameEditingSupport extends EditingSupport {

	  private final TableViewer viewer;
	  private final CellEditor editor;

	  public fileNameEditingSupport(TableViewer viewer) {
	    super(viewer);
	    this.viewer = viewer;
	    this.editor = new TextCellEditor(viewer.getTable());
	  }

	  @Override
	  protected CellEditor getCellEditor(Object element) {
	    return editor;
	  }

	  @Override
	  protected boolean canEdit(Object element) {
	    return true;
	  }

	  @Override
	  protected Object getValue(Object element) {
	    return ((File) element).getName();
	  }

	  @Override
	  protected void setValue(Object element, Object userInputValue) {
	    File orgFile = ((File) element);
	    System.out.println(String.valueOf(userInputValue));
	    System.out.println(String.valueOf(orgFile.getParent()));
	    
		orgFile.renameTo(new File(String.valueOf(orgFile.getParent() + userInputValue)));
	    //viewer.update(element, null);
	    viewer.refresh();
	  }
}
